package com.zm.demo.core.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author zoum
 * @create 2020/1/15 17:08
 */
public class ThreeSum {


    public static List<List<Integer>> threeSum(int[] nums) {

        int[][]dp = new int[nums.length-1][nums.length];

        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                dp[i][j] = nums[i] + nums[j];
            }
        }

        List<List<Integer>> list = new ArrayList<>();
        for (int i = 0; i < dp.length ; i++) {
            for (int j = i+1; j < dp[0].length ; j++) {
                for (int k = j+1; k < nums.length; k++) {
                    if (dp[i][j] + nums[k] == 0){
                        list.add(Arrays.asList(nums[i],nums[j],nums[k]));
                    }
                }
            }
        }

        return list;

    }


    public static void main(String[]args){
        threeSum(new int[]{-1,0,1,2,-1,-4});
    }
}
